package maximumCount;

class Solution {
    public int maximumCount(int[] nums) {
        //Pnumber负数的个数，Nnumber正数的个数
        int Pnumber=countPnumber(0,nums.length-1,nums);
        int Nnumber=countNnumber(0,nums.length-1,nums);
        return Math.max(Pnumber,Nnumber);

    }

    private int countNnumber(int left, int right, int[] nums) {
        while (left<=right){
            int mid=(left+right)/2;
            if(nums[mid]<=0){
                left=mid+1;
            }else {
                right=mid-1;
            }

        }
        //此时left处于第一个正数的位置，所以使用数组长度减去即可求出正数的个数
        return nums.length-left;
    }

    private int countPnumber(int left, int right, int[] nums) {
        while (left<=right){
            int mid=(left+right)/2;
            if(nums[mid]<0){
                left=mid+1;
            }else {
                right=mid-1;
            }
        }
        //此时right处于最后一个负数的位置，个数则为下标+1
        return right+1;
    }
}